/**
 * @file		statemachine.h
 * @brief		State Machine
 * @note		None
 * @attention	None
 * 
 * <B><I>ALL RIGHTS RESERVED, COPYRIGHT&copy; SOCIONEXT INCORPORATED 2016</I></B>
 */

/** @weakgroup statemachine_overview
@{
	State Machine base function.<br>
	<br>
	Used to customize the process in each state.<br>
	Refer to @ref customize "here" for "Customize".
@}*//* --- end of statemachine_overview */

#ifndef _STATEMACHINE_H_
#define _STATEMACHINE_H_

/** @weakgroup statemachine_definition
@{*/

/** state of state machine */
typedef enum {
	STATE_INIT = 0,				/**< Init state */
	STATE_LOAD,					/**< Load state */
	STATE_NORMAL,				/**< Normal state */
	STATE_SLEEP,				/**< Sleep state */
	STATE_STANDBY,				/**< Standby state */
	STATE_WAKEUP,				/**< Wakeup state */
#if defined(BOARD_TYPE_SNI_SMALL)
	STATE_TERM,					/**< Term state */
	STATE_DVFS_CHANGE,			/**< change dvfs voltage state */
	STATE_DVFS_FN_CHANGE,		/**< change dvfs function state */
#endif	// BOARD_TYPE_SNI_SMALL
	STATE_TEST1,					/**< Test state */
	STATE_TEST2,					/**< Test state */
	STATE_MAX
} E_STATEMACHINE_STATE;

/** State ater standby state */
typedef enum {
	STATE_AFTER_STANDY_WAIT = 0,	/**< keep standby state to wait for resume */
	STATE_AFTER_STANDY_WAKEUP,		/**< wakeup state */
	STATE_AFTER_STANDY_POWER_OFF,	/**< Power off state */
	STATE_AFTER_STANDY_ADJUST_DVFS,	/**< adjustment DVFS */
	STATE_AFTER_STANDY_DVFS_EN, /**< En/Dis Auto DVFS */
	STATE_AFTER_STANDY_MAX
} E_STATE_AFTER_STANDY;


/** action function at the end of each states */
typedef void (*ACT_FUNC)(void);

/* @} */	// statemachine_definition group

/** @weakgroup statemachine_func
@{*/

/**
Set state in state machine for inside task
@param [in]	state		@ref E_STATEMACHINE_STATE
@retval  0 : success
@retval -1 : failure. invalid state input
*/
int iStateMachineSetState(E_STATEMACHINE_STATE state);

/**
Set state in state machine for inside inerrupt handler
@param [in]	state		@ref E_STATEMACHINE_STATE
@retval  0 : success
@retval -1 : failure. invalid state input
*/
int iStateMachineSetStateFromISR(E_STATEMACHINE_STATE state);

/**
Get current state in state machine
@retval current state
*/
E_STATEMACHINE_STATE iStateMachineGetState();

/**
Set SYSTICK Enable/Disable.
@param [in]	enable		0:disable, 1:enable
*/
void vStateMachineSetSysTick(int enable);

/**
Set condition for Wakeup
@param [in] cond	enable bit field
*/
extern void vSetWakeupCondition( unsigned long cond );

/**
Set state after standby
@param [in] next_state	state after standby
@param [in] wait_time	(0):soon,  (other):waiting second
*/
extern int iSetStateAfterStandby( E_STATE_AFTER_STANDY next_state, unsigned wait_time, unsigned mode );

extern void vGetStateBootUpSource( unsigned char* status );
extern void vSetStandBy_Pmic( unsigned char standby_mode );
extern void vSetWakeUp_Pmic( unsigned char wakeup_mode );
/* @} */	// statemachine_func group

// aDvfs =============================---------------------------
extern int vAdvfs_DvfsSetEN(unsigned char *cmd);
extern int vAdvfsSetDate(unsigned char *cmd);
extern int SetPLL1FrqBuffer(unsigned *cmd);

extern void vAdvfs_DvfsGetEN(unsigned *cmd);
extern void vAdvfsGetDate(unsigned *cmd);
extern void GetPLL1FrqBuffer(unsigned *cmd);
extern unsigned char GetMappingTblVal(void);

#endif	// _STATEMACHINE_H_
